package com.team.panicgame;

import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.team.panicgame.models.gareve.Ship;
import com.team.panicgame.models.gareve.WallSegment;

public class Utils {

	public static boolean onTop(Rectangle r1, Rectangle r2) {
		return r1.y > (r2.y + r2.height) && Math.abs(r1.y - (r2.y + r2.height)) <= 2f &&
				((r1.x >= r2.x && r1.x <= r2.x + r2.width) || (r1.x + r1.width >= r2.x && r1.x + r1.width <= r2.x + r2.width));
	}

	public static boolean wallCollisionWithShip(WallSegment wall,Ship ship) {
		if(Intersector.intersectSegments(wall.p1, wall.p2, ship.p1, ship.p2, null))return true;
		if(Intersector.intersectSegments(wall.p1, wall.p2, ship.p2, ship.p3, null))return true;
		if(Intersector.intersectSegments(wall.p1, wall.p2, ship.p3, ship.p1, null))return true;
		
		return false;
	}
	
	public static Vector2 rotateAround(Vector2 point,Vector2 center,float angle){
		float x = point.x - center.x;
		float y = point.y - center.y;
		
		angle = (float) (angle * Math.PI / 180f);
		
		float dx = (float) (x * Math.cos(angle) - y * Math.sin(angle));
		float dy = (float) (x * Math.sin(angle) + y * Math.cos(angle));
		
		x = dx + center.x;
		y = dy + center.y;
		return new Vector2(x,y);
	}
	
}
